import 'package:flutter/material.dart';

class GridViewDemo1 extends StatefulWidget {
  const GridViewDemo1({Key? key}) : super(key: key);

  @override
  _GridViewDemo1State createState() => _GridViewDemo1State();
}

class _GridViewDemo1State extends State<GridViewDemo1> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('网格布局'),
      ),
      body: GridView(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3, mainAxisSpacing: 10, crossAxisSpacing: 10),
        children: [
          Container(
            width: 80,
            height: 80,
            color: Colors.red,
          ),
          Container(
            width: 80,
            height: 80,
            color: Colors.blue,
          ),
          Container(
            width: 80,
            height: 80,
            color: Colors.yellow,
          ),
          Container(
            width: 80,
            height: 80,
            color: Colors.black,
          ),
        ],
      ),
    );
  }
}
